package application;

import java.sql.Connection;

import ranking.GeneralRanking;
import JDBC.DatabaseDao;
import Service.UserService;
import Utils.FileUtils;
import dao.StatusDao;
import dao.UserDao;

public class Statistic {
	static Connection con = DatabaseDao.getConnection();
	static int topNumber = 10;

	public static void generateGeneralReport() {
		int usersCount = UserService.getCount();
		int maleUsersCount = UserService.getMaleCount();
		int verifiedUsersCount = UserService.getVerifiedCount();
		String fileContent = "";
		fileContent += "|*********************Sina Statistical Reports*********************\n\n";
		fileContent += "-------------------Users Related-------------------\n";
		fileContent += "\nA:Basic Information\n";
		fileContent += "1.users:" + usersCount + "\n";
		fileContent += "2.users(male):" + maleUsersCount + "\n";
		fileContent += "3.users(female):" + (usersCount - maleUsersCount) + "\n";
		fileContent += "4.users(verified):" + verifiedUsersCount + "\n";
		fileContent += "5.users(un-verified):" + (usersCount - verifiedUsersCount) + "\n";
		fileContent += "6.users system join time:\n" + UserDao.getSysJoinTimeRange() + "\n";

		fileContent += "\nB:Average Values and Variances\n";
		fileContent += "1.avg followers count:" + UserService.getAVGFollowersCount() + "\n";
		fileContent += "2.avg friends count:" + UserService.getAVGFriendsCount() + "\n";
		// fileContent += "3.avg favourites count:"
		// + UserService.getAVGFavouritesCount() + "\n";
		fileContent += "4.avg statuses count:" + UserService.getAVGStatusesCount() + "\n";
		// fileContent += "5.avg retweets count:" +UserDao.getAVGRetweetsCount()
		// + "\n";
		// fileContent += "6.avg comments count:"
		// +UserDao.getAVGCommentsCount()+ "\n";
		//
		fileContent += "7.variance followers count:" + UserDao.getVarianceByCondition("followers_count") + "\n";
		fileContent += "8.variance friends count:" + UserDao.getVarianceByCondition("friends_count") + "\n";
		// fileContent += "9.variance favourites count:"
		// + UserDao.getVarianceByCondition("favourites_count") + "\n";
		fileContent += "10.variance statuses count:" + UserDao.getVarianceByCondition("statuses_count") + "\n";
		//
		FileUtils.write("generalReport.txt", fileContent);

	}

	/**
	 * generate basic statistics of the corpus, file name "statisticsReport.txt"
	 */
	public static void generateReport() {
		String fileContent = "";
		fileContent += "\nC:User Rankings\n";
		fileContent += "1.users ranking by statuses:\n" + GeneralRanking.userRanking2String(GeneralRanking.getUserRankingByStatusesCount(Statistic.topNumber)) + "\n";
		fileContent += "2.users ranking by followers:\n" + GeneralRanking.userRanking2String(GeneralRanking.getUserRankingByFollowersCount(Statistic.topNumber)) + "\n";
		fileContent += "3.users ranking by friends:\n" + GeneralRanking.userRanking2String(GeneralRanking.getUserRankingByFriendsCount(Statistic.topNumber)) + "\n";
		fileContent += "4.users ranking by favorites:\n" + GeneralRanking.userRanking2String(GeneralRanking.getUserRankingByFavouritesCount(Statistic.topNumber)) + "\n";
		// fileContent += "5.users ranking by tags:\n" +
		// GeneralRanking.getUserRankingByTagCount(Statistic.topNumber) + "\n";
		// fileContent += "6. users ranking by status frequency:\n" +
		// GeneralRanking.getUserRankingByAVGStatusInterval(Statistic.topNumber)
		// + "\n";
		// fileContent += "7. users ranking by comments frequency:\n" +
		// GeneralRanking.getUserRankingByAVGCommentInterval(Statistic.topNumber)
		// + "\n";
		// fileContent += "8. users ranking by reciprocity count:\n" +
		// GeneralRanking.getUserRankingByReciprocitiesCount(Statistic.topNumber)
		// + "\n";
		// fileContent += "9. users ranking by reciprocity count:\n" +
		// GeneralRanking.getUserRankingByCommentsCount(Statistic.topNumber) +
		// "\n";
		// fileContent += "4.users ranking by favorites:\n"
		// + GeneralRanking.userRanking2String(GeneralRanking
		// .getUserRankingByFavouritesCount(Statistic.topNumber))
		// + "\n";
		// fileContent += "5.users ranking by tags:\n"
		// + GeneralRanking.getUserRankingByTagCount(Statistic.topNumber)
		// + "\n";
		// fileContent += "6. users ranking by status frequency:\n"
		// + GeneralRanking
		// .getUserRankingByAVGStatusInterval(Statistic.topNumber)
		// + "\n";
		// fileContent += "7. users ranking by comments frequency:\n"
		// + GeneralRanking
		// .getUserRankingByAVGCommentInterval(Statistic.topNumber)
		// + "\n";
		// fileContent += "8. users ranking by reciprocity count:\n"
		// + GeneralRanking
		// .getUserRankingByReciprocitiesCount(Statistic.topNumber)
		// + "\n";
		// fileContent += "9. users ranking by reciprocity count:\n"
		// + GeneralRanking
		// .getUserRankingByCommentsCount(Statistic.topNumber)
		// + "\n";
		fileContent += "-------------------Statuses Related-------------------\n";
		// fileContent += "1.crawled time:" + StatusDao.getCrawledTimeRange() +
		// "\n";
		// fileContent += "2.created time:" + StatusDao.getCreatedTimeRange() +
		// "\n";
//		fileContent += "1.crawled time:" + StatusDao.getCrawledTimeRange() + "\n";
//		fileContent += "2.created time:" + StatusDao.getCreatedTimeRange() + "\n";
		// fileContent += "3.source types:" + StatusDao.getSourceTypes() + "\n";
		fileContent += "4.statuses(count):" + StatusDao.getCountByCondition(null) + "\n";
		// fileContent += "5.statuses(length):" + StatusDao.getALLLength() +
		// "\n";
		// fileContent += "6.statuses(word count):" +
		// StatusDao.getALLWordCount() + "\n";
		// fileContent += "7.average status length(length):" +
		// StatusDao.getAVGLength() + "\n";
		// fileContent += "8.average status (count):" +
		// UserDao.getAVGByCondition("statuses_count") + "\n";
		// fileContent += "9.average status length(word count):" +
		// StatusDao.getAVGWordCount() + "\n";
		// fileContent += "10. statuses ranking by comments:\n" +
		// StatusDao.getStatusRankingByComments(Statistic.topNumber) + "\n";
		fileContent += "5.statuses(length):" + StatusDao.getALLLength() + "\n";
		// fileContent += "6.statuses(word count):" +
		// StatusDao.getALLWordCount()
		// + "\n";
		fileContent += "7.average status length(length):" + StatusDao.getAVGLength() + "\n";
		fileContent += "8.average status (count):" + UserDao.getAVGByCondition("statuses_count") + "\n";
		// fileContent += "9.average status length(word count):"
		// + StatusDao.getAVGWordCount() + "\n";
		// fileContent += "10. statuses ranking by comments:\n"
		// + StatusDao.getStatusRankingByComments(Statistic.topNumber)
		// + "\n";
		fileContent += "-------------------Comments Related-------------------\n";
		// fileContent += "1.comments:" + CommentService.getCount() + "\n";

		fileContent += "-------------------Relations Related-------------------\n";
		// fileContent += "1.single direction relations:" +
		// UserRelationDao.getCount() + "\n";
		// fileContent += "2.reciprocities:" +
		// UserRelationDao.getReciprocityCount() + "\n";
		// fileContent += "1.single direction relations:"
		// + UserRelationDao.getCount() + "\n";
		// fileContent += "2.reciprocities:"
		// + UserRelationDao.getReciprocityCount() + "\n";
		fileContent += "-------------------Tags Related-------------------\n";
		// fileContent += "1.tags:" + TagDao.getCount() + "\n";

		// System.out.println(fileContent);
		// fileContent += "1.tags:" + TagDao.getCount() + "\n";
		//
		// System.out.println(fileContent);
		FileUtils.write("statisticsReport.txt", fileContent);

	}

	public static void main(String args[]) {
		// generateGeneralReport();
		// generateReport();
		// ArrayList<User> users =
		// GeneralRanking.getUserRankingByStatusesCount(10);
		// for (int i = 0; i < users.size(); i++)
		// System.out.println(users.get(i).getName());
		generateGeneralReport();
		generateReport();

	}
}
